package com.h819.core.web;

import com.h819.core.timer.TimerTaskExample;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import java.util.Timer;

/**
 * @ClassName: TimerListener
 * @Description: TODO(监听器，监听计划任务，详见 com.h819.core.timer.readme)
 * @author h819
 * @date Aug 19, 2009 10:40:52 PM
 * @version V1.0
 */

//此监听器中，只设置一个时间间隔即可
public class TimerListener implements ServletContextListener {

	private Timer timer = null;

	int second = 60*60;
	int time = second * 1000;//毫秒

	public void contextInitialized(ServletContextEvent event) {
		timer = new Timer(true);
		//设置任务计划，启动时间和间隔时间(毫秒)
		timer.schedule(new TimerTaskExample(), 0, time);
	}

	public void contextDestroyed(ServletContextEvent event) {
		timer.cancel();
	}

}
